package com.fulu.game.bi.controller.dispatch;

import com.fulu.game.bi.entity.dto.ExposurePlayeeDetailListDTO;
import com.fulu.game.bi.entity.dto.ExposurePlayeeOverviewListDTO;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.common.NameMsgVO;
import com.fulu.game.bi.service.impl.dispatch.PlayeeExposureStatServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 陪玩师曝光
 */
@RequestMapping("/api/v1/exposure/playee")
@RestController
public class PlayeeExposureStatController {

    @Autowired
    private PlayeeExposureStatServiceImpl playeeExposureStatService;

    /**
     * 陪玩师曝光总览-实时数据
     */
    @PostMapping("/overview-realtime")
    public Result overviewRealtime() {
        return Result.success().data(playeeExposureStatService.overviewRealtime());
    }

    /**
     * 陪玩师曝光总览-列表
     */
    @PostMapping("/overview-list")
    public Result overviewList(ExposurePlayeeOverviewListDTO dto) {
        return Result.success().data(playeeExposureStatService.overviewList(dto));
    }

    /**
     * 陪玩师曝光总览-导出
     */
    @PostMapping("/overview-export")
    public void overviewListExport(ExposurePlayeeOverviewListDTO dto) {
        playeeExposureStatService.overviewListExport(dto);
    }

    /**
     * 陪玩师曝光总览-折线图
     */
    @PostMapping("/overview-line-chart")
    public Result stat() {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        cacheMap.put("曝光人数", "exposureUserNum");
        cacheMap.put("曝光次数", "exposureNum");
        cacheMap.put("主页浏览人数", "homePageUserNum");
        cacheMap.put("主页浏览次数", "homePageNum");
        cacheMap.put("下单人数", "orderUserNum");
        cacheMap.put("下单次数", "orderNum");

        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    return idNameVO;
                })
                .collect(Collectors.toList());
        list.add(new NameMsgVO("ctr", "CTR", "percent"));
        list.add(new NameMsgVO("cvr", "CVR", "percent"));
        return Result.success().data(list).msg("获取成功");
    }

    /**
     * 陪玩师曝光数据-列表
     */
    @PostMapping("/detail-list")
    public Result detailList(ExposurePlayeeDetailListDTO dto) {
        return Result.success().data(playeeExposureStatService.detailList(dto));
    }

    /**
     * 陪玩师曝光数据-导出
     */
    @PostMapping("/detail-export")
    public void detailExport(ExposurePlayeeDetailListDTO dto) {
        playeeExposureStatService.detailExport(dto);
    }
}
